package com.wang.other_test.redisTest;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Calendar;

/**
 * @author: lvyan
 * @date: 2023/1/29
 * @description:
 */
public class RedisTest {

        private static final String ADDR = "127.0.0.1";

        private static final int PORT = 6379;

        private static JedisPool jedisPool = new JedisPool(ADDR, PORT);

        public static Jedis getJedis() {
            return jedisPool.getResource();
        }

        //生产者,生成5个订单放进去
        public void productionDelayMessage() {
            for (int i = 0; i < 5; i++) {
                //延迟3秒
                Calendar cal1 = Calendar.getInstance();
                cal1.add(Calendar.SECOND, 3);
                int second3later = (int) (cal1.getTimeInMillis() / 1000);
                //key,score,value
                RedisTest.getJedis().zadd("OrderId", second3later, "OID0000001" + i);
                System.out.println(System.currentTimeMillis() + "ms:redis生成了一个订单任务：订单ID为" + "OID0000001" + i);
            }
        }

}
